<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
        @import "http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css";
        @import "http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.css"
    </style>
    <script type="text/javascript" src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"
            djConfig="parseOnLoad: true"></script>
    <script>
        dojo.require("dojo.data.ItemFileWriteStore");
        dojo.require("dijit.Tree");
        dojo.require("dojo.parser");
        dojo.require("dojo.dnd.Source");
        dojo.require("dijit._tree.dndSource");
       
        function poptartCheckItemAcceptance(node,source) {
            // Get the associated dojo.data item for the target
            item = dijit.getEnclosingWidget(node).item;
            // Need to check for item because when dropping on a root node,
            // item === null
            if (! item) return false;
           
            ptType = ptTree.store.getValue(item,"type");
           
            if (ptType == 'category') {
                // We make intelligent guesses about the correct folder
                re = new RegExp(ptTree.store.getValue(item,"regexp"));
                okToMove = true;
                for (var itemId in source.selection) {
                   console.debug(itemId+" tested against "+re.toString());
                   okToMove &= re.test(itemId);
                }
               return okToMove;
            }
            else
                return false;
        }
   </script>
   
</head>
<body class="tundra">
        <div>Drag a Pop Tart to Its Category</div>
        <div dojoType="dojo.dnd.Source">
           <div class="dojoDndItem" id="Hot Chocolate">Hot Chocolate</div>
           <div class="dojoDndItem" id="Blueberry">Blueberry</div>
        </div>
        <div dojoType="dojo.data.ItemFileWriteStore"
             url="poptarts_dnd.txt" jsid="popStore" />
        <div dojoType="dijit.Tree" store="popStore" labelAttr="name"
             label="Pop Tarts" jsid="ptTree"
             dndController="dijit._tree.dndSource"
             checkItemAcceptance="poptartCheckItemAcceptance">
        </div>
</body>
</html>